package com.cory.module.msg.admin;

import java.util.List;
import com.cory.boot.utils.CommonData;
import com.cory.module.msg.admin.annotation.AdminMsgSettings;
import com.cory.utils.lang.StringUtils;

/**
 * @author xiongcong
 * @date 2022-09-17
 */
public class AdminMsgService {
    
    public List<AdminMsg> getMyAdminMsgs() {
        return AdminMsgClient.getAllAdminMsgs();
    }
    
    public void initPlatformAdminMsg() {
        String system = CommonData.getEnvConfig("admin.msg.system");
        List<AdminMsg> list = AdminMsgClient.getAllAdminMsgs();
        
        for (AdminMsg msg : list) {
            AdminMsgSettings settings = msg.settings();
            
            if (!"platform".equals(settings.type())) {
                continue;
            }
            if (StringUtils.isBlank(system) || system.equals(settings.system())) {
                msg.reloadMsg();
            }
        }
    }
    
    public void initUserAdminMsg() {
        String system = CommonData.getEnvConfig("admin.msg.system");
        List<AdminMsg> list = AdminMsgClient.getAllAdminMsgs();
        
        for (AdminMsg msg : list) {
            AdminMsgSettings settings = msg.settings();
            
            if (!"user".equals(settings.type())) {
                continue;
            }
            if (StringUtils.isBlank(system) || system.equals(settings.system())) {
                msg.reloadMsg();
            }
        }
    }
}
